﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RVEAd.Business;
using RVEAd.Business.Model;

namespace RVEAd.Forms
{
    public partial class FormAlegeClient : Form
    {
        private RveBL rveBL;
        
        public Client SelectedClient { get; private set; }

        public FormAlegeClient()
        {
            InitializeComponent();
            this.Load += new EventHandler(FormAlegeClient_Load);
        }

        void FormAlegeClient_Load(object sender, EventArgs e)
        {
            rveBL = new RveBL();

            dataGridClient.AutoGenerateColumns = false;
            dataGridClient.DataSource = rveBL.GetClients();
        }

        private void tbSearchClient_TextChanged(object sender, EventArgs e)
        {
            dataGridClient.DataSource = rveBL.GetClientsStartWith(tbSearchClient.Text);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.SelectedClient = null;
            this.Close();
        }

        private void btnSelecteaza_Click(object sender, EventArgs e)
        {
            SelecteazaClient();
        }


        private void SelecteazaClient()
        {
            this.SelectedClient = (Client)dataGridClient.CurrentRow.DataBoundItem;
            this.Close();
        }

        private void dataGridClient_DoubleClick(object sender, EventArgs e)
        {
            SelecteazaClient();
        }
    }
}
